(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.lookup.stopPaymentController', stopPaymentController);
	stopPaymentController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig',
			'authService' ];
	function stopPaymentController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, authService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("invoiceLookup");
		ctrl.dialogsModule = dialogsModule;
		ctrl.layoutConfig = layoutConfig;
		ctrl.ok = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['ok'] || dialogsModule.btnCallback['ok'](ctrl.selectedRows) !== false) {
				$uibModalInstance.close();
			}
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
		ctrl.init = function() {
			//title
			ctrl.dialogsModule.title = ctrl.dialogsModule.title;
			if (ctrl.dialogsModule.params.operation != null && "R" == ctrl.dialogsModule.params.operation){
				ctrl.dialogsModule.title = "title.revokestoppayment.lookup";
			}
			
			ctrl.gridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.tableConfigs.table, rowSelectionChanged);
			ctrl.gridOptions.data = 'vm.stopPayment.allList';
			ctrl.gridOptions.multiSelect = true;
			
			ctrl.stopPayment = {};
			ctrl.stopPayment.filterMemberIds = [];
			if (ctrl.dialogsModule.params.memberIds) {
				angular.forEach(ctrl.dialogsModule.params.memberIds, function(id, index) {
					ctrl.stopPayment.filterMemberIds.push(id);
				});
			}
			if (ctrl.dialogsModule.params.operation) {
				ctrl.stopPayment.operation = ctrl.dialogsModule.params.operation;
			}
			authService.search(ctrl.stopPayment).then(function(response) {
				angular.merge(ctrl.stopPayment, response.data);
				gridService.updateGridOptions(ctrl.stopPayment.memberList, ctrl.gridOptions);
			}, angular.noop);
		};

		function rowSelectionChanged(eventRow, selectedRows) {
			ctrl.selectedRows = selectedRows;
		}

		
	}
})(angular);